/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author gabrielbmoro
 */
public class Professor extends Usuario {

    public Professor() {
        super.table = "professor";
    }

    public Professor(String nome) {
        this.nome = nome;
        super.table = "professor";
    }

    @Override
    public ArrayList<String> acessarPerfil(int id) {
        String sql = "select nome,email from " + super.table + " where idprofessor=" + id + ";";
        try {
            this.conecta = ConectaBD.getInstance();
            super.statement = this.conecta.getConnection().createStatement();
            super.resultSet = super.statement.executeQuery(sql);
            ArrayList<String> resultado = new ArrayList<>();
            while (super.resultSet.next()) {
                resultado.add(super.resultSet.getString(1));
                resultado.add(super.resultSet.getString(2));
                resultado.add("Universidade Federal do Pampa");
            }
            super.resultSet.close();
            super.statement.close();
            return resultado;
        } catch (SQLException sqlErro) {
            sqlErro.printStackTrace();
        }
        return null;
    }

    public int recuperarIdProfessor() {
        try {
            String sql = "select idprofessor from " + super.table + " where nome=\"" + this.nome + "\";";
            super.conecta = ConectaBD.getInstance();
            super.statement = super.conecta.getConnection().createStatement();
            super.resultSet = super.statement.executeQuery(sql);
            int id = 0;
            while (super.resultSet.next()) {
                id = super.resultSet.getInt(1);
            }
            return id;
        } catch (SQLException ex) {

        } finally {

        }
        return 0;
    }
    
    public String recuperaNomeProfessor(int id){
        try {
            String sql = "select nome from " + super.table + " where idprofessor=" + id + ";";
            super.conecta = ConectaBD.getInstance();
            super.statement = super.conecta.getConnection().createStatement();
            super.resultSet = super.statement.executeQuery(sql);
            String nome=null;
            while (super.resultSet.next()) {
                nome = super.resultSet.getString(1);
            }
            return nome;
        } catch (SQLException ex) {

        } finally {

        }
        return null;
    }
}
